package com.thinklib.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @module 加载外部图片资源
 * 图书logo存在磁盘上，该配置可以让磁盘图片目录被纳入到static目录下
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {

	@Value("${img.upload.url}")
    private String imgUploadUrl;

    @Value("${user.avatar.url}")
    private String userAvatarUrl;
	
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	registry.addResourceHandler("/book_avatar/**").addResourceLocations("file:" + imgUploadUrl).addResourceLocations("classpath:/static/");
    	registry.addResourceHandler("/user_avatar/**").addResourceLocations("file:" + userAvatarUrl).addResourceLocations("classpath:/static/");
    }
}
